package com.tong.hao.ac.service.component.account;

import cn.buddha.jec.model.TongContext;
import cn.buddha.jec.util.TongStringUtils;
import com.tong.hao.ac.db.entity.AcUser;
import com.tong.hao.ac.db.service.IAcUserService;
import com.tong.hao.ac.service.domain.account.AcUserReqDo;
import com.tong.hao.ac.service.domain.account.AcUserResDo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName AcUserComponent
 * @Author 友野浩二
 * @Date 2020/5/3 15:48
 * @Description 用户组件
 * @Version 1.0
 */
@Component
public class AcUserComponent {

    /**
     * 用户信息 服务
     */
    @Resource
    private IAcUserService acUserServiceImpl;

    /**
     * @return com.tong.hao.ac.service.domain.account.AcUserResDo
     * @Author 友野浩二
     * @Description // 用户注册组件
     * @Date 2020/5/3 17:02
     * @Param [acUserReqDo 用户模型]
     */
    public AcUserResDo registerAcUser(AcUserReqDo acUserReqDo) {
        TongContext tongContext = TongContext.getInstance();

        // 用户注册
        AcUser acUser = new AcUser();
        acUser.setAcName(acUserReqDo.getAcName());
        acUser.setAge(acUserReqDo.getAge());
        acUser.setEmail(acUserReqDo.getEmail());
        acUser.setPhone(acUserReqDo.getMobile());
        acUser.setInnerNum(tongContext.getTranDate() + tongContext.getFlowableId());

        // 用户注册
        this.acUserServiceImpl.save(acUser);

        AcUserResDo acUserResDo = new AcUserResDo();
        acUserResDo.setInnerNum(acUser.getInnerNum());
        return acUserResDo;
    }

}
